
<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		
		<title></title>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../surprise/css/app.css" />
		<link href="../css/mui.imageviewer.css" rel="stylesheet" />
		<link href="../surprise/css/config.css" rel="stylesheet" type="text/css" />
			<link rel="stylesheet" href="../css/font-awesome-4.7.0/css/font-awesome.min.css">
		<style>
			html,
			body {
				height: 100%;
				margin: 0px;
				padding: 0px;
				overflow: hidden;
				-webkit-touch-callout: none;
				-webkit-user-select: none;
			}
			footer {
				position: fixed;
				width: 100%;
				height: 50px;
				min-height: 50px;
				border-top: solid 1px #bbb;
				left: 0px;
				bottom: 0px;
				overflow: hidden;
				/* padding: 0px 50px; */
				background-color: #fafafa;
			}
			.footer-left {
			    float: left;
			    /* width: 50px; */
				width: 10%;
			    height: 50px;
			    left: 0px;
			    bottom: 0px;
			    text-align: center;
			    vertical-align: middle;
			    line-height: 100%;
			    padding: 12px 4px;
			}
			.footer-right {
			    float: left;
			    /* width: 24px; */
				width: 8%;
			    height: 40px;
			    right: 0px;
			    bottom: 0px;
			    text-align: center;
			    vertical-align: middle;
			    line-height: 100%;
			    padding: 12px 5px;
			    display: inline-block;
			}
			.footer-center {
			    /* width: 256px; */
					width: 67%;
			    float: left;
			    height: 100%;
			    padding: 5px 0px;
			}
			.footer-center [class*=input] {
				width: 100%;
				height: 100%;
				border-radius: 5px;
			}
			.footer-center .input-text {
			    background: #fff;
			    border: solid 1px #ddd;
			    padding: 10px !important;
			    font-size: 16px !important;
			    line-height: 18px !important;
			    font-family: verdana !important;
			    overflow: hidden;
			    text-align: center;
			}
			.footer-center .input-sound {
				background-color: #eee;
			}
			.mui-content {
				height: 100%;
				padding: 44px 0px 50px 0px;
				overflow: auto;
				background-color: #eaeaea;
			}
			#msg-list {
				/* height: 100%;
				overflow: auto; */
				-webkit-overflow-scrolling: touch;
			}
			.msg-item {
				padding: 8px;
				clear: both;
			}
			.msg-item .mui-item-clear {
				clear: both;
			}
			.msg-item .msg-user {
				width: 38px;
				height: 38px;
				border: solid 1px #d3d3d3;
				display: inline-block;
				background: #fff;
				border-radius: 3px;
				vertical-align: top;
				text-align: center;
				float: left;
				padding: 3px;
				color: #ddd;
			}
			
			.msg-item .msg-user-img{
				width: 38px;
				height: 38px;
				display: inline-block;
				border-radius: 3px;
				vertical-align: top;
				text-align: center;
				float: left;
				color: #ddd;
			}
			
			.msg-item .msg-content {
				display: inline-block;
				border-radius: 5px;
				border: solid 1px #d3d3d3;
				background-color: #FFFFFF;
				color: #333;
				padding: 8px;
				vertical-align: top;
				font-size: 15px;
				position: relative;
				margin: 0px 8px;
				max-width: 75%;
				min-width: 35px;
				float: left;
			}
			.msg-item .msg-content .msg-content-inner {
				overflow-x: hidden;
			}
			.msg-item .msg-content .msg-content-arrow {
				position: absolute;
				border: solid 1px #d3d3d3;
				border-right: none;
				border-top: none;
				background-color: #FFFFFF;
				width: 10px;
				height: 10px;
				left: -5px;
				top: 12px;
				-webkit-transform: rotateZ(45deg);
				transform: rotateZ(45deg);
			}
			.msg-item-self .msg-user,
			.msg-item-self .msg-content {
				float: right;
			}
			.msg-item-self .msg-content .msg-content-arrow {
				left: auto;
				right: -5px;
				-webkit-transform: rotateZ(225deg);
				transform: rotateZ(225deg);
			}
			.msg-item-self .msg-content,
			.msg-item-self .msg-content .msg-content-arrow {
				background-color: #4CD964;
				color: #fff;
				border-color: #2AC845;
			}
			footer .mui-icon {
				color: #000;
			}
			footer .mui-icon:active {
				color: #007AFF !important;
			}
			footer .mui-icon-paperplane:before {
				content: "发送";
			}
			footer .mui-icon-paperplane {
				/*-webkit-transform: rotateZ(45deg);
				transform: rotateZ(45deg);*/
				
				font-size: 16px;
				word-break: keep-all;
				line-height: 100%;
				padding-top: 6px;
				color: rgba(0, 135, 250, 1);
			}
			#msg-sound {
				-webkit-user-select: none !important;
				user-select: none !important;
			}
			.rprogress {
				position: absolute;
				left: 50%;
				top: 50%;
				width: 140px;
				height: 140px;
				margin-left: -70px;
				margin-top: -70px;
				background-image: url(../images/arecord.png);
				background-repeat: no-repeat;
				background-position: center center;
				background-size: 30px 30px;
				background-color: rgba(0, 0, 0, 0.7);
				border-radius: 5px;
				display: none;
				-webkit-transition: .15s;
			}
			.rschedule {
				background-color: rgba(0, 0, 0, 0);
				border: 5px solid rgba(0, 183, 229, 0.9);
				opacity: .9;
				border-left: 5px solid rgba(0, 0, 0, 0);
				border-right: 5px solid rgba(0, 0, 0, 0);
				border-radius: 50px;
				box-shadow: 0 0 15px #2187e7;
				width: 46px;
				height: 46px;
				position: absolute;
				left: 50%;
				top: 50%;
				margin-left: -23px;
				margin-top: -23px;
				-webkit-animation: spin 1s infinite linear;
				animation: spin 1s infinite linear;
			}
			.r-sigh{
				display: none;
				border-radius: 50px;
				box-shadow: 0 0 15px #2187e7;
				width: 46px;
				height: 46px;
				position: absolute;
				left: 50%;
				top: 50%;
				margin-left: -23px;
				margin-top: -23px;
				text-align: center;
				line-height: 46px;
				font-size: 40px;
				font-weight: bold;
				color: #2187e7;
			}
			.rprogress-sigh{
				background-image: none !important;
			}
			.rprogress-sigh .rschedule{
				display: none !important;
			}
			.rprogress-sigh .r-sigh{
				display: block !important;
			}
			.rsalert {
				font-size: 12px;
				color: #bbb;
				text-align: center;
				position: absolute;
				border-radius: 5px;
				width: 130px;
				margin: 5px 5px;
				padding: 5px;
				left: 0px;
				bottom: 0px;
			}
			@-webkit-keyframes spin {
				0% {
					-webkit-transform: rotate(0deg);
				}
				100% {
					-webkit-transform: rotate(360deg);
				}
			}
			@keyframes spin {
				0% {
					transform: rotate(0deg);
				}
				100% {
					transform: rotate(360deg);
				}
			}
			#h {
				background: #fff;
				border: solid 1px #ddd;
				padding: 10px !important;
				font-size: 16px !important;
				font-family: verdana !important;
				line-height: 18px !important;
				overflow: visible;
				position: absolute;
				left: -1000px;
				right: 0px;
				word-break: break-all;
				word-wrap: break-word;
			}
			.cancel {
				background-color: darkred;
			}
			#msg-type{
				color: #d92727;
				    font-size: 7vw;
			}
			#msg-type33{
				color: #d92727;
				    font-size: 7vw;
			}
			.mui-bar {
				 background: #0080C0;
			}
			
			.mui-publish-vedio {
			    position: relative;
			    background-color: #f7f7f7;
			    display: inline-block;
			    width: 100%;
			    height: 76px;
			    padding-top: 14px;
			    border: 1px solid red;
			}
			.mui-publish-vedio .mui-file {
			    position: absolute;
			    left: 0;
			    top: 0;
			    width: 100%;
			    height: 100%;
			    opacity: 0;
			}
			.mui-publish-vedio .mui-vedio-phone {
			    width: 22px;
			    height: 19px;
			    margin-bottom: 16px;
			}
			#previewcontioner{
				position: fixed;
				    bottom: 0px;
					width: 100%;
			}
			#personImg img{
				width: 50px;
				height: 50px;
				border-radius: 10px;
				border: 1px solid #f4eeee;
			}
			.getsurprise{
				width: 100%;
				text-align: center;
				color: grey;
				 font-size: 3.5vw;
			}
			.msg-user-img-right{
				
				    width: 38px;
				    height: 38px;
				    display: inline-block;
				    border-radius: 3px;
				    vertical-align: top;
				    text-align: center;
				    float: right;
				    color: #ddd;
			}
			#qiang{
				display: none;
				position: absolute;
				left: 0px;
				top: 0px;
				width: 100%;
				height: 100%;
				background-color: #1e1c1c99;
			}
			#qiang1{
				position: absolute;
				left: 20%;
				top: 20%;
				width: 60%;
				height:60%;
				background-color: rgba(255, 0, 0, 0.45);
				    border-radius: 30px;
			}
			#qiang2{
				position: absolute;
				 width: 100%;
				 text-align: center;
				top: 40%;
				color: black;
				font-size: 7vw;
			}
			#qiang3{
				position: absolute;
				    /* left: 50%; */
				    top: 50%;
				    text-align: center;
				    color: black;
				    width: 100%;
				    font-size: 14vw;
			}
			.upload_img{
				width: 80%;
				    height: 78px;
				    position: absolute;
				    opacity: 0;
					top: 0px;
					    left: 0px;
			}
			#myselfface{
				position: fixed;
				    bottom: 0px;
					width: 100%;
					background-color: white;
			}
		</style>
	</head>

	<body contextmenu="return false;">
		<header class="mui-bar mui-bar-nav">
			<a class=" mui-icon mui-icon-left-nav mui-pull-left" style="color: white;" href="../surprise/chathome.html"></a>
			<h1 class="mui-title" id="title" style="color: white;">聊惊喜 </h1>
			<a id="menu" class="mui-icon mui-icon-plusempty mui-pull-right" href="../surprise/chatcontrall.html"  style="color: white;"></a>
		</header>
		<pre id='h'></pre>
		<script id='msg-template' type="text/template">
			<% for(var i in record){ var item=record[i]; %>
				<div class="msg-item <%= (item.sender=='self'?' msg-item-self':'') %>" msg-type='<%=(item.type)%>'>
					<!-- msg-content='<%=(item.content.replace(/"/g,''))%>'-->
					<% if(item.sender=='self' ) { %>
						<!-- <i class="msg-user mui-icon mui-icon-person"></i> ../surprise/images/jnav02.jpg,../surprise/images/jnav04.jpg-->
						<img class="msg-user-img-right" src="<%=(item.img)%>" alt="" onerror="javascript:this.src='../surprise/images/默认头像.jpg';"/>
					<% } else { %>
						<img class="msg-user-img" src="<%=(item.img)%>" alt="" onerror="javascript:this.src='../surprise/images/默认头像.jpg';"/>
					<% } %>
					<div class="msg-content">
						<div class="msg-content-inner">
							<% if(item.type=='text' ) { %>
								<%==( item.content|| '&nbsp;&nbsp;') %>
							<% } else if(item.type=='image' ) { %>
								<img class="msg-content-image dada" src="<%=(item.content)%>" style="max-width: 100px;" />
							<% } else if(item.type=='surprise' ) { %>
								<img isCan="false" data-name="<%=(item.name)%>" orderNoChild="<%=(item.orderNoChild)%>" data- class="msg-content-image surprise" src="<%=(item.content)%>" style="max-width: 100px;" />
							<% } else if(item.type=='getsurprise' ) { %>
							<img class="msg-content-image getsurprise" src="<%=(item.content)%>" style="max-width: 100px;" />
							
							<% } else if(item.type=='sound' ) { %>
								<span class="mui-icon mui-icon-mic" style="font-size: 18px;font-weight: bold;"></span>
								<span class="play-state">点击播放</span>
							<% } %>
						</div>
						<div class="msg-content-arrow"></div>
					</div>
					<div class="mui-item-clear"></div>
				</div>
			<% } %>
		</script>
		<div class="mui-content">
			<div id='msg-list'>
			</div>
		</div>
		<footer id="footer">
			<div class="footer-left" id="fotterleft">
				<i id='msg-image' class="mui-icon mui-icon-mic" style="font-size: 28px;-webkit-text-stroke: 1px #d92727;"></i>
			</div>
			<div class="footer-center">
				<!-- <textarea id='msg-text' type="text" class='input-text' placeholder="请输入内容"></textarea> -->
				<div id='msg-text'  type="text" class='input-text msg-text' placeholder="请输入祝福内容"  contenteditable="true" style="-webkit-user-select:text;"></div>
				
				<button id='msg-sound' type="button" class='input-sound' style="display: none;">按住说话</button>
			</div>
			<label id="send0" for="" class="footer-right">
				<i id='msg-type33' class="fa fa-smile-o mui-icon "></i>
				
			</label>
			<label id="send1"  for="" class="footer-right">
				<i id='msg-type2' class="mui-icon mui-icon-plus" style="-webkit-text-stroke: 1px #d92727;"></i>
				 
			</label>
			<label id="send2"  for="" class="footer-right">
				<button id="sendbtn" type="button" class='mui-btn-primary' style="height: 30px;">发送</button>
				</label>
				
		</footer>
		<div id="previewcontioner"  class="mui-clearfix mui-row-bottom mui-padbom-10" style="display: none;">
			<!--预览的图片-->
			<div id="preview">
			<!--<span class="mui-pull-left mui-phone-preview">
				<a href="javascript:void(0);" class="mui-icon-remove"></a>
				<img src="../images/img1.png" class="mui-img-response"/>
			</span>
			<span class="mui-pull-left mui-phone-preview">
				<a href="javascript:void(0);" class="mui-icon-remove"></a>
				<img src="../images/img1.png" class="mui-img-response"/>
			</span>-->
			</div>
			<!--上传图片-->
			<!-- <span class="mui-publish-vedio mui-text-center mui-pull-left">
				<form role="form" id="myForm" action="" method="post" enctype="multipart/form-data">
						<input type="file" name="fulAvatar" class="mui-file upload_img" onchange="uploadByForm(this)">
					</form>
				<img src="../surprise/images/tab_vediodark_icon.png" class="mui-vedio-phone">
				<p class="mui-vedio-text">图片 / 视频/语音</p>
			</span> -->
			<ul class="mui-table-view mui-grid-view" id="personImg">
					        <li class="mui-table-view-cell mui-media mui-col-xs-3">
					            <a >
					                <img class="mui-media-object" src="../newdetails/images/logo_no.png">
					                <div class="mui-media-body">相册</div>
									<form role="form" id="myForm" action="" method="post" enctype="multipart/form-data">
																<input type="file" name="file" class="mui-file upload_img" onchange="uploadByForm(this)">
															</form>	
									
									
									</a>
									
							
									
									
								</li>
									
					        <li class="mui-table-view-cell mui-media mui-col-xs-3">
					            <a href="#">
					                <img class="mui-media-object" src="../newdetails/images/photo.png">
					                <div class="mui-media-body">视频</div></a></li>
					        <li class="mui-table-view-cell mui-media mui-col-xs-3">
					            <a href="#"><img id="img_carmea" class="mui-media-object" src="../newdetails/images/tab_saoyisao_icon.png">
					                <div class="mui-media-body">拍摄</div></a></li>
					        
									<li class="mui-table-view-cell mui-media mui-col-xs-3">
									    <a href="#" id="pickli">
											
									        <img class="mui-media-object" src="../newdetails/images/user_activity.png">
									        <div class="mui-media-body">发礼品</div></a>
									</li>
					    </ul>   
		</div>
		<div id="myselfface"  class="mui-clearfix mui-row-bottom mui-padbom-10" style="display: none;">
			
			<div class=" myselfface"></div>
		</div>
		<div id='sound-alert' class="rprogress">
			<div class="rschedule"></div>
			<div class="r-sigh">!</div>
			<div id="audio_tips" class="rsalert">手指上滑，取消发送</div>
		</div>
		
		<div id="qiang">
			<div id="qiang1">
				
			</div>
			<div  id="qiang2">抢礼品</div>
			<div  id="qiang3">开</div>
		</div>
		
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../surprise/js/jquery.min.js"></script>
		<!-- <script src="http://139.199.15.148:8084/socket.io/socket.io.js"></script> -->
		<!-- <script src="../js/socket.js"></script> -->
		<script src="/socket.io/socket.io.js">
		<script src="../js/mui.imageViewer.js"></script>
		<script src="../js/arttmpl.js"></script>
		<script src="../js/path.js"></script>
			<script src="../js/layer.js"></script>
			<script type="text/javascript" src="../js/face.js"></script>
		<script type="text/javascript" charset="utf-8">
			
			// function escape(e){
			// 	return e;
			// }
			//template.config('escape', false);
			var isShow = false;
			document.getElementById("msg-type2").addEventListener("tap",function(){
				isShow=!isShow;
				if(isShow){
					//isShow = true;
					// document.getElementById("previewcontioner").style.display="";
					$("#previewcontioner").show();
					$("#footer").css("bottom","98px");
					setTimeout(function(){
						$("#pickli").attr("href","../surprise/qiangliping.html");
					},200)
				}else{
					//isShow = false;
					// document.getElementById("previewcontioner").style.display="none";
					$("#previewcontioner").hide();
					$("#footer").css("bottom","0px");
					$("#pickli").attr("href","#");
				}
				$("#myselfface").hide();
				isClick=false;
			})
			document.getElementById("msg-text").addEventListener('input',function(){
				//$("#send0").hide();
				$("#send0").show();
				$("#send1").hide();
				$("#fotterleft").css("width","33px");
			})
			document.getElementById("send2").addEventListener('input',function(){
				
			});
			
			var isClick=false;
			document.getElementById('send1').addEventListener('tap',function(){
				isClick = !isClick;
				if(isClick){
					$("#previewcontioner").show();
					$("#footer").css("bottom","98px");
					setTimeout(function(){
						$("#pickli").attr("href","../surprise/qiangliping.html");
					},200)
				}else{
					$("#previewcontioner").hide();
					$("#footer").css("bottom","0px");
					$("#pickli").attr("href","#");
				}
				
			});
			var isSound=false;
			document.getElementById('msg-image').addEventListener('tap',function(){
				// console.log("---");
				if(!isSound){
					$("#msg-sound").show();
					$("#msg-text").hide();
				}else{
					$("#msg-sound").hide();
					$("#msg-text").show();
				}
				
				isSound=!isSound;
				isShow = false;
				document.getElementById("previewcontioner").style.display="none";
			})
			var isShow1=false;
			console.log($('#footer #msg-type33')[0]);
			$('#footer #msg-type33')[0].addEventListener('tap',function(){
				if(!isShow1){
					isShow1 = true;
					$("#myselfface").show();
					$("#footer").css("bottom","151px");
					$(".send1").hide();
					$(".send2").show();
					
				}else{
					isShow1 = false;
					$("#myselfface").hide();
					
					$("#footer").css("bottom","0px");
					$(".send1").show();
					$(".send2").hide();
				}
				$("#previewcontioner").hide();
			})
			//---------------------------表情-----------------------------------
			$('#footer #msg-type33').qqFace({ 
					id:"myselfface",
			        assign:'footer #msg-text', //给输入框赋值 
			        path:'http://www.jq22.com/demo/qqFace/arclist/'    //表情图片存放的路径 
			    }); 
			//表情符号
			
			
			(function($, doc) {
				var MIN_SOUND_TIME = 800;
				$.init({
					gestureConfig: {
						tap: true, //默认为true
						doubletap: true, //默认为false
						longtap: true, //默认为false
						swipe: true, //默认为true
						drag: true, //默认为true
						hold: true, //默认为false，不监听
						release: true //默认为false，不监听
					}
				});
				template.config('escape', false);
				 // console.log(template)
				if(mui.os.ios){
					// 解决在ios上fixed元素focusin时位置出现错误的问题 
					document.addEventListener('DOMContentLoaded',function(){
						var footerDom = document.querySelector('footer');
						
						document.addEventListener('focusin', function() {
							footerDom.style.position = 'absolute';
						});
						document.addEventListener('focusout', function() {
							footerDom.style.position = 'fixed';
						});
					});
				}

				$.plusReady(function() {
					plus.webview.currentWebview().setStyle({
						softinputMode: "adjustResize"
					});
					var showKeyboard = function() {
						if ($.os.ios) {
							var webView = plus.webview.currentWebview().nativeInstanceObject();
							webView.plusCallMethod({
								"setKeyboardDisplayRequiresUserAction": false
							});
						} else {
							var Context = plus.android.importClass("android.content.Context");
							var InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");
							var main = plus.android.runtimeMainActivity();
							var imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
							imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
							//var view = ((ViewGroup)main.findViewById(android.R.id.content)).getChildAt(0);
							imm.showSoftInput(main.getWindow().getDecorView(), InputMethodManager.SHOW_IMPLICIT);
							//alert("ll");
						}
					};
					var record = [{
						// sender: 'zs',
						// type: 'text',
						// content: 'Hi，我是 惊喜到 小管家！'
					}];
					var ui = {
						body: doc.querySelector('body'),
						footer: doc.querySelector('footer'),
						footerRight: doc.querySelector('.footer-right'),
						footerLeft: doc.querySelector('#img_carmea'),
						btnMsgType: doc.querySelector('#msg-type'),
						boxMsgText: doc.querySelector('#msg-text'),
						boxMsgSound: doc.querySelector('#msg-sound'),
						btnMsgImage: doc.querySelector('#img_carmea'),
						areaMsgList: doc.querySelector('#msg-list'),
						boxSoundAlert: doc.querySelector('#sound-alert'),
						h: doc.querySelector('#h'),
						content: doc.querySelector('.mui-content')
					};
					ui.h.style.width = ui.boxMsgText.offsetWidth + 'px';
					//alert(ui.boxMsgText.offsetWidth );
					var footerPadding = ui.footer.offsetHeight - ui.boxMsgText.offsetHeight;
					var msgItemTap = function(msgItem, event) {
						var msgType = msgItem.getAttribute('msg-type');
						var msgContent = msgItem.getAttribute('msg-content')
						if (msgType == 'sound') {
							player = plus.audio.createPlayer(msgContent);
							var playState = msgItem.querySelector('.play-state');
							playState.innerText = '正在播放...';
							player.play(function() {
								playState.innerText = '点击播放';
							}, function(e) {
								playState.innerText = '点击播放';
							});
						}
					};
					// var imageViewer = new $.ImageViewer('.msg-content-image', {
					// 	dbl: false
					// });
					var bindMsgList = function() {
						//绑定数据:
						/*tp.bind({
							template: 'msg-template',
							element: 'msg-list',
							model: record
						});*/
						// ui.areaMsgList.innerHTML = template('msg-template', {
						// 	"record": record
						// });
						var msgItems = ui.areaMsgList.querySelectorAll('.msg-item');
						[].forEach.call(msgItems, function(item, index) {
							item.addEventListener('tap', function(event) {
								msgItemTap(item, event);
							}, false);
						});
						// imageViewer.findAllImage();
						ui.areaMsgList.scrollTop = ui.areaMsgList.scrollHeight + ui.areaMsgList.offsetHeight;
					};
					bindMsgList();
					window.addEventListener('resize', function() {
						ui.areaMsgList.scrollTop = ui.areaMsgList.scrollHeight + ui.areaMsgList.offsetHeight;
					}, false);
					var send = function(msg) {
						record.push(msg);
						bindMsgList();
						toRobot(msg.content);
					};
					var toRobot = function(info) {
						var apiUrl = 'http://www.tuling123.com/openapi/api';
						$.getJSON(apiUrl, {
							"key": 'acfbca724ea1b5db96d2eef88ce677dc',
							"info": info,
							"userid": plus.device.uuid
						}, function(data) {
							//alert(JSON.stringify(data));
							record.push({
								sender: 'zs',
								type: 'text',
								content: data.text
							});
							bindMsgList();
						});
					};

					function msgTextFocus() {
							ui.boxMsgText.focus();
							setTimeout(function() {
								ui.boxMsgText.focus();
							}, 150);
						}
						//解决长按“发送”按钮，导致键盘关闭的问题；
					ui.footerRight.addEventListener('touchstart', function(event) {
						if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
							msgTextFocus();
							event.preventDefault();
						}
					});
					//解决长按“发送”按钮，导致键盘关闭的问题；
					ui.footerRight.addEventListener('touchmove', function(event) {
						if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
							msgTextFocus();
							event.preventDefault();
						}
					});
					//					ui.footerRight.addEventListener('touchcancel', function(event) {
					//						if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
					//							msgTextFocus();
					//							event.preventDefault();
					//						}
					//					});
					//					ui.footerRight.addEventListener('touchend', function(event) {
					//						if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
					//							msgTextFocus();
					//							event.preventDefault();
					//						}
					//					});
					ui.footerRight.addEventListener('release', function(event) {
						if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
							//showKeyboard();
							ui.boxMsgText.focus();
							setTimeout(function() {
								ui.boxMsgText.focus();
							}, 150);
							//							event.detail.gesture.preventDefault();
							send({
								sender: 'self',
								type: 'text',
								content: ui.boxMsgText.value.replace(new RegExp('\n', 'gm'), '<br/>')
							});
							ui.boxMsgText.value = '';
							$.trigger(ui.boxMsgText, 'input', null);
						} else if (ui.btnMsgType.classList.contains('mui-icon-mic')) {
							ui.btnMsgType.classList.add('mui-icon-compose');
							ui.btnMsgType.classList.remove('mui-icon-mic');
							ui.boxMsgText.style.display = 'none';
							ui.boxMsgSound.style.display = 'block';
							ui.boxMsgText.blur();
							document.body.focus();
						} else if (ui.btnMsgType.classList.contains('mui-icon-compose')) {
							ui.btnMsgType.classList.add('mui-icon-mic');
							ui.btnMsgType.classList.remove('mui-icon-compose');
							ui.boxMsgSound.style.display = 'none';
							ui.boxMsgText.style.display = 'block';
							//--
							//showKeyboard();
							ui.boxMsgText.focus();
							setTimeout(function() {
								ui.boxMsgText.focus();
							}, 150);
						}
					}, false);
					ui.footerLeft.addEventListener('tap', function(event) {
						var btnArray = [{
							title: "拍照"
						}, {
							title: "从相册选择"
						}];
						plus.nativeUI.actionSheet({
							title: "选择照片",
							cancel: "取消",
							buttons: btnArray
						}, function(e) {
							var index = e.index;
							switch (index) {
								case 0:
									break;
								case 1:
									var cmr = plus.camera.getCamera();
									cmr.captureImage(function(path) {
										send({
											sender: 'self',
											type: 'image',
											content: "file://" + plus.io.convertLocalFileSystemURL(path)
										});
									}, function(err) {});
									break;
								case 2:
									plus.gallery.pick(function(path) {
										send({
											sender: 'self',
											type: 'image',
											content: path
										});
									}, function(err) {}, null);
									break;
							}
						});
					}, false); 
					var setSoundAlertVisable=function(show){
						if(show){
							ui.boxSoundAlert.style.display = 'block';
							ui.boxSoundAlert.style.opacity = 1;
						}else{
							ui.boxSoundAlert.style.opacity = 0;
							//fadeOut 完成再真正隐藏
							setTimeout(function(){
								ui.boxSoundAlert.style.display = 'none';
							},200);
						}
					};
					var recordCancel = false;
					var recorder = null;
					var audio_tips = document.getElementById("audio_tips");
					var startTimestamp = null;
					var stopTimestamp = null;
					var stopTimer = null;
					// alert(1)
					ui.boxMsgSound.addEventListener('hold', function(event) {
						
						recordCancel = false;
						if(stopTimer)clearTimeout(stopTimer);
						audio_tips.innerHTML = "手指上划，取消发送";
						ui.boxSoundAlert.classList.remove('rprogress-sigh');
						setSoundAlertVisable(true);
						recorder = plus.audio.getRecorder();
						if (recorder == null) {
							plus.nativeUI.toast("不能获取录音对象");
							return;
						}
						startTimestamp = (new Date()).getTime();
						recorder.record({
							filename: "_doc/audio/"
						}, function(path) {
							if (recordCancel) return;
							send({
								sender: 'self',
								type: 'sound',
								content: path
							});
						}, function(e) {
							plus.nativeUI.toast("录音时出现异常: " + e.message);
						});
					}, false);
					ui.body.addEventListener('drag', function(event) {
						//console.log('drag');
						if (Math.abs(event.detail.deltaY) > 50) {
							if (!recordCancel) {
								recordCancel = true;
								if (!audio_tips.classList.contains("cancel")) {
									audio_tips.classList.add("cancel");
								}
								audio_tips.innerHTML = "松开手指，取消发送";
							}
						} else {
							if (recordCancel) {
								recordCancel = false;
								if (audio_tips.classList.contains("cancel")) {
									audio_tips.classList.remove("cancel");
								}
								audio_tips.innerHTML = "手指上划，取消发送";
							}
						}
					}, false);
					ui.boxMsgSound.addEventListener('release', function(event) {
						//console.log('release');
						if (audio_tips.classList.contains("cancel")) {
							audio_tips.classList.remove("cancel");
							audio_tips.innerHTML = "手指上划，取消发送";
						}
						//
						stopTimestamp = (new Date()).getTime();
						if (stopTimestamp - startTimestamp < MIN_SOUND_TIME) {
							audio_tips.innerHTML = "录音时间太短";
							ui.boxSoundAlert.classList.add('rprogress-sigh');
							recordCancel = true;
							stopTimer=setTimeout(function(){
								setSoundAlertVisable(false);
							},800);
						}else{
							setSoundAlertVisable(false);
						}
						recorder.stop();
					}, false);
					ui.boxMsgSound.addEventListener("touchstart", function(e) {
						//console.log("start....");
						e.preventDefault();
					});
					ui.boxMsgText.addEventListener('input', function(event) {
						ui.btnMsgType.classList[ui.boxMsgText.value == '' ? 'remove' : 'add']('mui-icon-paperplane');
						ui.btnMsgType.setAttribute("for", ui.boxMsgText.value == '' ? '' : 'msg-text');
						ui.h.innerText = ui.boxMsgText.value.replace(new RegExp('\n', 'gm'), '\n-') || '-';
						ui.footer.style.height = (ui.h.offsetHeight + footerPadding) + 'px';
						ui.content.style.paddingBottom = ui.footer.style.height;
					});
					var focus = false;
					ui.boxMsgText.addEventListener('tap', function(event) {
						ui.boxMsgText.focus();
						setTimeout(function() {
							ui.boxMsgText.focus();
						}, 0);
						focus = true;
						setTimeout(function () {
							focus = false;
						},1000);
						event.detail.gesture.preventDefault();
					}, false);
					//点击消息列表，关闭键盘
					ui.areaMsgList.addEventListener('click',function (event) {
						if(!focus){
							ui.boxMsgText.blur();
						}
					})
					
					
				});
			}(mui, document));
			document.getElementById("title").innerHTML = getQueryString("title");
			
			var type = getQueryString("type");
			if(type=="3"){
				//$("#menu").hide();
				$("#menu").removeClass("mui-icon-plusempty");
				$("#menu").addClass("mui-icon-more");
				$("#menu").attr("href","../surprise/person.html");
			}
			
			function getQueryString(name) {
				//console.log(name);
			    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
			    var r = window.location.search.substr(1).match(reg);
			    //console.log(r);
			    if (r != null) {
			        //转码方式改成 decodeURI
			        return decodeURI(r[2]);
			    }
			    return null;
			}
			/* var msg=template('msg-template', {
				"record": [{sender:'self' ,type:"image",content:'../surprise/images/jDingdan002.jpg'}
				
				,{sender:'' ,type:"text",content:'开始抢礼品了'},
				,{sender:'' ,type:"surprise",content:'../surprise/images/send.jpg?t=1'}
				]
			})
			$("#msg-list").append(msg); */
			var whoname = "";//谁的礼品
			addEvent();
			var order_no_child=null;
			function addEvent(){
				$(".surprise").on('tap',function(e){
					if($(e.currentTarget).attr("isCan")=="false"){
						return;
					}
					console.log("您开始抢到了礼品",$(e.currentTarget).attr("getsurprise"));
					whois = $(e.currentTarget).attr("data-name");
					if($(e.currentTarget).attr("getsurprise")!="true"){
						$("#qiang").show();
						//$("#msg-list").append("<div class='getsurprise'>您抢到了张三的<a href='../surprise/qianglist.html'>礼品</a></div>");
						//e.currentTarget["getsurprise"]="true";
						$(e.currentTarget).attr("getsurprise","true")
						order_no_child=$(e.currentTarget).attr("order_no_child")
						
						
					}else{
						mui.openWindow("../surprise/qianglist.html?order_no_child="+$(e.currentTarget).attr("order_no_child"))
					}
					
					
				});
				$(".getsurprise").on('tap',function(e){
					mui.openWindow("../surprise/getsurprise.html")
				});
				$(".dada").on('tap',function(e){
					previewImage([e.target.src])
				});
				
			}
			
			
			$("#qiang3").on('tap',function(e){	
				
				addGrapGifts(order_no_child,function(data){
					if(data&&data.code==202){
						//已经抢完了
						mui.toast("已经抢完了");
						$("#qiang").hide();
					}else if(data&&data.code==200){
						sendMessageGrapGifts(function(){
							$("#qiang").hide();
							/* $("#msg-list").append("<div class='getsurprise'>您抢到了"+whois+"的<a href='../surprise/qianglist.html'>礼品</a></div>");
							var msgs=template('msg-template', {
								"record": [{sender:'self' ,type:"getsurprise",content:'../surprise/images/sendsus.jpg',img:myImg}
								
								]
							})
							$("#msg-list").append(msgs); */
							queryPerson(order_no_child);
							$(".getsurprise").on('tap',function(e){
								mui.openWindow("../surprise/getsurprise.html")
							});
						});
					
						
					}
					
				});
				
				
			});
			$(".msg-user-img").on('tap',function(e){
				if(type=="3"){
					mui.openWindow("../surprise/person.html")
				}else{
					mui.openWindow("../surprise/personinfor.html")
				}
				
			});
			$(".msg-user-img-right").on('tap',function(e){
				
				if(type=="3"){
					mui.openWindow("../surprise/person.html?myslef=true")
				}else{
					mui.openWindow("../surprise/personinfor.html?myslef=true")
				}
			});
			//console.log(msg);
			var myImg="";
			var msgList = [];//保存从历史信息库读取下来的聊天记录
			var currentTime = "";//当前记录的会话时间点
			var isLogin = false;
			//var myid = "13428975459";
			//var group_id = "20180717193552366152440306118705";
			var myid = getQueryString("phone");//localStorage.telephone;
			//var group_id = "20180717193552366152440306118705";
			var group_id = getQueryString("groupid");
			localStorage.groupid=group_id;
			// var socket = io('http://139.199.15.148:8084');
			// var socket = io("/im");
			var socket = io("");
			 socket.on('confirm_connect', function (data) {
			  
			     console.log(data);
			     socket.emit('login_event', { id: myid });//+Math.ceil(Math.random()*1000)
			 	socket.emit('userInfo_event', { myid: myid});
			 	//socket.emit('putUserInfo_event', { myid: getParamName('id') ,username:getParamName('store_name'),nickname:nick_nameheadImg:getParamName('head_img')});
			 	
			 	socket.emit('putGroupInfo_event', { myid: myid ,group_id:group_id});
			 	
			   });
			  socket.on('once', function (data) {
			     console.log(data);
					var item={};
					item.type="text";
			 		var srr = data.data_msg.substr(6).split(':@&@_:');
			 		if(srr[1]==4)
			 		srr[2] = HTMLEncode(srr[2]);
			 		if(srr[1]==3){
			 				//srr[2]  = '<img  onclick="showImg(\''+srr[2]+'\')" src="'+srr[2] +'">';
			 				$('#showImg').click(function(e){
			 						$('#showImg').hide();
			 						callWeex("true");//通知weex其他控件开启显示
			 				  });
							   item.type="image";
			 			}else if(srr[1]==5){ //地图信息
			 				var point = srr[2].split("|");
			 				var src = "http://api.map.baidu.com/staticimage/v2?ak=gu5AiO7bQnCFw5twluR17MtPgSHsa9aR&width=750&height=900&zoom=15&center="+point[1]+","+point[0]+"&scale=1.5&markers="+point[1]+","+point[0];
			 				srr[2]  = '<img  onclick="showPos(\''+point[1]+'\',\''+point[0]+'\')" src="'+ src +'">';
			 				$('#showImg').click(function(e){
			 						$('#showImg').hide();
			 						callWeex("true");
			 				  });
			 			}else if(srr[1]==6)//视频
			 			{
			 				srr[2]  = '<video width="185" height="150" controls  class="video-js" data-setup="{}">'
			 						  +'<source src="'+ srr[2] +'" type="video/mp4">'
			 						  // +'<source src="movie.ogg" type="video/ogg">'
			 						 +'您的浏览器不支持Video标签。'
			 						 +'</video>';
			 			}else if(srr[1]==88){
							item.type="surprise";
						}else if(srr[1]==89){
							item.type="getsurprise";
						}
			 		
			 	 if(currentTime!=srr[0].substring(0,16)){
			 	 console.log("---------------------------------------",srr[0]);
			 				currentTime = srr[0].substring(0,16);
			 				 // $('#contioner').append('<section class="system J-mjrlinkWrap J-cutMsg"><div class="msg-system" >'+currentTime+'</div></section>');
			 			
						
								$("#msg-list").append("<div class='getsurprise'>"+currentTime+"</div>");
						
						}	
			 		
			 	// $('#contioner').append('<section class="user"><div>'+srr[2]+'</div><span>'+nick_name+'</span><img class="headImg" onclick="showImg('+myImg+')" src = "'+myImg+'" alt="图片XX" onerror="this.src=\'http://app.aimeng.tech:8081/bootpage/icon.png\';this.onerror=null"></section>');
			 			var msg=template('msg-template', {
			 				"record": [
			 				//	{sender:'self' ,type:"image",content:'../surprise/images/jDingdan002.jpg'}
			 				
			 				{sender:'self' ,type:item.type,name:userObj[myid].username,content:srr[2],img:myImg},
			 				//,{sender:'' ,type:"surprise",content:'../surprise/images/send.jpg?t=1'}
			 				]
			 			})
			 			$("#msg-list").append(msg);
						
						scrollToEnd();
						addEvent();
						
						//调用查询抢礼品的
						startQueryGrapGifts();
			   });
			   var  currentOtherId ;//当前给我发送的人的id
			    var otherImg = "";//当前给我发送的人的头像
			    var userObj = {};
			     var otherName = "";
			   //别人发给我的
			   socket.on('Tomeonce', function (data) {
			     console.log('别人发给我的：',data);
			 	$('#allmap').click(function(){
			 		$('#allmap').hide();
			 	});
			 	
			 	currentOtherId = data.id;
			 	var srr = data.data_msg.substr(6).split(':@&@_:');
				var item={};
				item.type="text";
			 	if(userObj[currentOtherId]){
			 		otherImg = userObj[currentOtherId].headImg;
			 		otherName = userObj[currentOtherId].username;
			 		if(srr[1]==4)
			 		srr[2] = HTMLEncode(srr[2]);
			 		else if(srr[1]==3){
			 				//srr[2]  = '<img onclick="showImg(\''+srr[2]+'\')"  src="'+srr[2] +'">';
			 				$('#showImg').click(function(e){
			 						$('#showImg').hide();
			 						callWeex("true");
			 				  });
							  item.type="image";
			 			}else if(srr[1]==5){ //地图信息
			 				var point = srr[2].split("|");
			 				var src = "http://api.map.baidu.com/staticimage/v2?ak=gu5AiO7bQnCFw5twluR17MtPgSHsa9aR&width=750&height=900&zoom=15&center="+point[1]+","+point[0]+"&scale=1.5&markers="+point[1]+","+point[0];
			 				srr[2]  = '<img  onclick="showPos(\''+point[1]+'\',\''+point[0]+'\')" src="'+ src +'">';
			 				$('#showImg').click(function(e){
			 						$('#showImg').hide();
			 						callWeex("true");
			 				  });
			 			}else if(srr[1]==6)//视频
			 			{
			 				srr[2]  = '<video width="185" height="150" controls  class="video-js" data-setup="{}">'
			 						  +'<source src="'+ srr[2] +'" type="video/mp4">'
			 						  // +'<source src="movie.ogg" type="video/ogg">'
			 						 +'您的浏览器不支持Video标签。'
			 						 +'</video>';
			 			}else if(srr[1]==88){
							item.type="surprise";
						}else if(srr[1]==89){
							item.type="getsurprise";
						}
			 		if(currentTime!=srr[0].substring(0,16)){
			 				currentTime = srr[0].substring(0,16);
			 				 $('#contioner').append('<section class="system J-mjrlinkWrap J-cutMsg"><div class="msg-system" >'+currentTime+'</div></section>');
			 			}	
			 		
			 		//$('#contioner').append('<section class="service"><img class="headImg" src = "'+otherImg+'" alt="图片XX" onerror="this.src=\'http://app.aimeng.tech:8081/bootpage/icon.png\';this.onerror=null"><span>'+otherName+'</span><div>'+srr[2]+'</div></section>');
						var msg=template('msg-template', {
							"record": [
							//	{sender:'self' ,type:"image",content:'../surprise/images/jDingdan002.jpg'}
							
							{sender:'' ,type:item.type,name:otherName,content:srr[2],img:otherImg},
							//,{sender:'' ,type:"surprise",content:'../surprise/images/send.jpg?t=1'}
							]
						})
						$("#msg-list").append(msg);
			 		scrollToEnd();
			 	}else{
			 			 $.ajax({
			              type: "POST",
			              url: "/getUserInfo",
			              data: {myid:currentOtherId},
			              dataType: "json",
			              success: function(data){
			 			
			 					userObj[currentOtherId] = data.data;
			 					 userObj[currentOtherId].myid = currentOtherId;
			 				otherImg = userObj[currentOtherId].headImg;
			 				otherName = userObj[currentOtherId].username;
			 			if(srr[1]==4)
			 				srr[2] = HTMLEncode(srr[2]);
			 			else if(srr[1]==3){
			 				//srr[2]  = '<img onclick="showImg(\''+srr[2]+'\')"  src="'+srr[2] +'">';
			 				$('#showImg').click(function(e){
			 						$('#showImg').hide();
			 						callWeex("true");
			 				  });
							   item.type="image";
			 			}else if(srr[1]==5){ //地图信息
			 				var point = srr[2].split("|");
			 				var src = "http://api.map.baidu.com/staticimage/v2?ak=gu5AiO7bQnCFw5twluR17MtPgSHsa9aR&width=750&height=900&zoom=15&center="+point[1]+","+point[0]+"&scale=1.5&markers="+point[1]+","+point[0];
			 				srr[2]  = '<img  onclick="showPos(\''+point[1]+'\',\''+point[0]+'\')" src="'+ src +'">';
			 				$('#showImg').click(function(e){
			 						$('#showImg').hide();
			 						callWeex("true");
			 				  });
			 			}else if(srr[1]==6)//视频
			 			{
			 				srr[2]  = '<video width="185" height="150" controls  class="video-js" data-setup="{}">'
			 						  +'<source src="'+ srr[2] +'" type="video/mp4">'
			 						  // +'<source src="movie.ogg" type="video/ogg">'
			 						 +'您的浏览器不支持Video标签。'
			 						 +'</video>';
			 			}else if(srr[1]==88){
							item.type="surprise";
						}else if(srr[1]==89){
							item.type="getsurprise";
						}
			 			
			 			if(currentTime!=srr[0].substring(0,16)){
			 				currentTime = srr[0].substring(0,16);
			 				 $('#contioner').append('<section class="system J-mjrlinkWrap J-cutMsg"><div class="msg-system" >'+currentTime+'</div></section>');
			 			}	
			 		
			 			
			 		//$('#contioner').append('<section class="service"><img class="headImg"  src = "'+otherImg+'" alt="图片XX" onerror="this.src=\'http://app.aimeng.tech:8081/bootpage/icon.png\';this.onerror=null"><span>'+otherName+'</span><div>'+srr[2]+'</div></section>');
			 			var msg=template('msg-template', {
			 				"record": [
			 				//	{sender:'self' ,type:"image",content:'../surprise/images/jDingdan002.jpg'}
			 				
			 				{sender:'' ,type: item.type,name:otherName,content:srr[2],img:otherImg},
			 				//,{sender:'' ,type:"surprise",content:'../surprise/images/send.jpg?t=1'}
			 				]
			 			})
			 			$("#msg-list").append(msg);
			 			scrollToEnd();
			 			}});
			 	}
			 	
			 	addEvent();
			 	
			 	//调用查询抢礼品的
			 	startQueryGrapGifts();
			     
			   });
			   
			   
			   //获取用户可以是别人也可以是自己的消息
			   socket.on('userInfo_event', function (data) {
			     console.log(data);
			    
			   });
			   socket.on('putUserInfo_callback', function (data) {
			     console.log('更新客户信息成功',data);
			     
			   });
			  
			  
			   
			   //添加成功信息回调
			   socket.on('putGroupInfo_callback', function (data) {
			     console.log(data);
			     /* $.ajax({
			              type: "POST",
			              url: "/once",
			              data: {myid:getParamName('id'), otherid:getParamName('otherid'),msgType:4,data_msg:'尼玛你妹的qq'},
			              dataType: "json",
			              success: function(data){
			                         console.log(data);
			                       }
			          });*/
			 		 if( isLogin)return;
			 		  isLogin = true;
			 		 $.ajax({
			              type: "POST",
			              url: "/im/queryGroupUserInfo",
			              data: {group_id:group_id},
			              dataType: "json",
			              success: function(data){
			                         console.log(data);
			 						// $('#otherName').html('您正在与美容院客户 '+data.data.username+" 聊天");
			 						 
			                      var ulist = data.data;
			 					
			 					for( var i=0;i<ulist.length;i++ ){
			 						var item = ulist[i];
			 						userObj[item.myid] = item;
			 						if(myid == item.myid){
			 							myImg = item.headImg;
			 						}
			 					}
			 		 
			 		 
			 		 
			 		  $.ajax({
			              type: "POST",
			              url: "/im/queryGroupHistory",
			              data: {group_id:group_id},
			              dataType: "json",
			              success: function(data){
			                  console.log(data);
			 				 if(data.data&&data.data.length>0){
			 				 
			 					var evt = new Event('queryGroupHistory')
			 					evt.data = { name: 'speces', data: data}
			 					document.dispatchEvent(evt)
			 				 
			 				 
			 				 
			 					var  record ="";// data.data.record;
			 					
			 					var myidFlag = [];
			 					
			 					for( var i=0,m=data.data.length; i<m ;i++ ){
			 						record += data.data[i].record+":&@&_:"+data.data[i].last_time+":@&@_:"+data.data[i].last_type+":@&@_:"+data.data[i].last_word+":@&@_:*";
			 						myidFlag.push(data.data[i].myid);
			 					}
			 					var myid_this = myidFlag.shift();
			 					 var list = record.split(':&@&_:');
			 					 console.log(list);
			 					 for( var i=0,m= list.length; i< m;i++ ){
			 						//if(list[i].length<2)continue;
			 						if(list[i].indexOf(':@&@_:')==-1)continue;
			 						var srr = list[i].split(':@&@_:');
			 						//$('#contioner').append('<section class="user"><div>'+srr[2]+'</div><span>'+'自己'+'</span><img src = "'+otherImg+'" alt="图片XX" onerror="this.src=\'http://app.aimeng.tech:8081/bootpage/icon.png\';this.onerror=null"></section>');
			 						msgList.push( { 'content':srr[2], 'myid':myid_this, 'time':srr[0],'msgType':srr[1] , 't':convertDateFromString(srr[0]).getTime(),time:srr[0]} );//type=0表示自己对别人的聊天，1表示别人对自己的聊天
			 						if(srr[3]=='*'){
			 							myid_this = myidFlag.shift();
			 						}
			 					 }
			 					 //-------------------------------------查询别人对自己聊的天---------------------------------------------------------
			 								/* $.ajax({
			 									 type: "POST",
			 									 url: "/queryHistory",
			 									 data: {myid:getParamName('otherid'), otherid:getParamName('id')},
			 									 dataType: "json",
			 									 success: function(data){
			 										 console.log(data);
			 										 if(data.data&&data.data.record){
			 											var  record = data.data.record;
			 											 var list = record.split(':&@&_:');
			 											 console.log(list);
			 											 for( var i=0,m= list.length; i< m;i++ ){
			 												if(list[i].length<2)continue;
			 												var srr = list[i].split(':@&@_:');
			 												//$('#contioner').append('<section class="service"><img src = "'+otherImg+'" alt="图片XX" onerror="this.src=\'http://app.aimeng.tech:8081/bootpage/icon.png\';this.onerror=null"><span>'+otherName+'</span><div>'+srr[2]+'</div></section>');
			 												msgList.push( { 'content':srr[2], 'type':1, 'time':srr[0],'msgType':srr[1], 't':convertDateFromString(srr[0]).getTime() } );
			 											 }
			 											 
			 											 doHistoryMsg();
			 										 }
			 										 
			 										 
			 									  }
			 								 });*/
			 					 
			 					 doHistoryMsg();
			 					 
			 				 }
			 				 
			 				 
			               }
			      
			     });
			 	
			 	
			 	//-------------------------
			 	 }
			          });
			 	//----------------------------
			 		
			   });
			   
			  var compare = function (prop) {
			     return function (obj1, obj2) {
			         var val1 = obj1[prop];
			         var val2 = obj2[prop];if (val1 < val2) {
			             return -1;
			         } else if (val1 > val2) {
			             return 1;
			         } else {
			             return 0;
			         }            
			     } 
			 }
			   
			   //处理历史数据信息
			   function doHistoryMsg(){
			 		msgList = msgList.sort(compare("t"));
			 		console.log(msgList);
			 		$('#contioner').empty();
				
			 	   for( var i = 0, m = msgList.length; i < m ; i++ ){
			 			var item = msgList[i];
			 			item.type="text";
			 			if(item.msgType==4)
			 			item.content = HTMLEncode(item.content);
			 			else if(item.msgType==3){
			 				//item.content = '<img class="msg-content-image" onclick="showImg(\''+item.content+'\')" src="'+item.content+'">';
			 				$('#showImg').click(function(e){
			 						$('#showImg').hide();
			 						callWeex("true");
			 				  });
							  item.type="image";
			 			}else if(item.msgType==5){ //地图信息
			 				var point = item.content.split("|");
			 				var src = "http://api.map.baidu.com/staticimage/v2?ak=gu5AiO7bQnCFw5twluR17MtPgSHsa9aR&width=750&height=900&zoom=15&center="+point[1]+","+point[0]+"&scale=1.5&markers="+point[1]+","+point[0];
			 				item.content  = '<img  onclick="showPos(\''+point[1]+'\',\''+point[0]+'\')" src="'+ src +'">';
			 				$('#showImg').click(function(e){
			 						$('#showImg').hide();
			 						callWeex("true");
			 				  });
			 			}else if(item.msgType==6)//视频
			 			{
			 				item.content = '<video width="185" height="150" controls  class="video-js" data-setup="{}">'
			 						  +'<source src="'+ item.content +'" type="video/mp4">'
			 						  // +'<source src="movie.ogg" type="video/ogg">'
			 						 +'您的浏览器不支持Video标签。'
			 						 +'</video>';
			 			}else if(item.msgType==88){
							//抢礼品
							//item.content='<img class="msg-content-image surprise" src="'+item.content+'" style="max-width: 100px;">';
							item.type="surprise";
						}else if(item.msgType==89){
							//抢礼品
							//item.content='<img class="msg-content-image surprise" src="'+item.content+'" style="max-width: 100px;">';
							item.type="getsurprise";
						}
			 			if(currentTime!=item.time.substring(0,16)){
			 				currentTime = item.time.substring(0,16);
			 				// $('#contioner').append('<section class="system J-mjrlinkWrap J-cutMsg"><div class="msg-system" >'+currentTime+'</div></section>');
			 			$("#msg-list").append("<div class='getsurprise'>"+currentTime+"</div>");
			 			
						
						}
			 			
			 			
			 			if(item.myid == myid){
			 				//$('#contioner').append('<section class="user"><div>'+item.content+'</div><span>'+nick_name+'</span><img class="headImg"  src = "'+myImg+'" alt="图片XX" onerror="this.src=\'http://app.aimeng.tech:8081/bootpage/icon.png\';this.onerror=null"></section>');
							var msg=template('msg-template', {
								"record": [
								//	{sender:'self' ,type:"image",content:'../surprise/images/jDingdan002.jpg'}
								{sender:'self' ,type:item.type,name:userObj[myid].username,content:item.content,img:myImg},
								//{sender:'self' ,type:"text",content:item.content,img:myImg},
								//,{sender:'' ,type:"surprise",content:'../surprise/images/send.jpg?t=1'}
								]
							})
							
							$("#msg-list").append(msg);
							//$("#msg-list .msg-item-self").
							// $("div[class=msg-item-self]:last").find(".msg-content-inner").html(item.content);
							console.log(item.content);
						}else{
			 				//$('#contioner').append('<section class="service"><img class="headImg"  src = "'+userObj[item.myid].headImg+'" alt="图片XX" onerror="this.src=\'http://app.aimeng.tech:8081/bootpage/icon.png\';this.onerror=null"><span>'+userObj[item.myid].username+'</span><div>'+item.content+'</div></section>');
							if(userObj[item.myid]&&userObj[item.myid].headImg){
								var msg=template('msg-template', {
									"record": [
									//	{sender:'self' ,type:"image",content:'../surprise/images/jDingdan002.jpg'}
									{sender:'' ,type:item.type,name:userObj[item.myid].username,content:item.content,img:userObj[item.myid].headImg},
									//{sender:'' ,type:"text",content:item.content,img:userObj[item.myid].headImg},
									//{sender:'' ,type:"text",content:item.content},
									//,{sender:'' ,type:"surprise",content:'../surprise/images/send.jpg?t=1'}
									]
								})
								$("#msg-list").append(msg);
								// $("div[class=msg-item-self]:last").find(".msg-content-inner").html(item.content);
							}else{
								var msg=template('msg-template', {
									"record": [
									//	{sender:'self' ,type:"image",content:'../surprise/images/jDingdan002.jpg'}
									
									//{sender:'' ,type:"text",content:item.content,img:userObj[item.myid].headImg},
									{sender:'' ,type:item.type,name:userObj[item.myid].username,content:item.content},
									//,{sender:'' ,type:"surprise",content:'../surprise/images/send.jpg?t=1'}
									]
								})
								$("#msg-list").append(msg);
								// $("div[class=msg-item-self]:last").find(".msg-content-inner").html(item.content);
							}
							
							
							
						}
			 			
			 	   }
			 	   
			 	  // $('#contioner').append('<section class="system J-mjrlinkWrap J-cutMsg"><div class="msg-system" id="otherName">---------------以上是历史消息---------------</div></section>');
			  
					$("#msg-list").append("<div class='getsurprise'>---------------以上是历史消息---------------</div>");
					
					addEvent();
					scrollToEnd();
					//调用查询抢礼品的
					startQueryGrapGifts();
					
					
			   }
			   
			   
			   function showImg(u){
			 	console.log(u);
			 	$('#showImg img').attr('src',u);
			 	$('#showImg').show();
			 	callWeex("false");
			   }
			   
			   function showPos(x,y){
			  // alert(x+'|'+y);
			 	var point = new BMap.Point(x, y);
			 	map.centerAndZoom(point, 15);
			 	map.clearOverlays();  
			 	var marker = new BMap.Marker(point);  // 创建标注
			 	map.addOverlay(marker);               // 将标注添加到地图中
			 	marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
			 	$('#allmap').show();
			 	callWeex("false");
			 	scrollToTop();
			   }
			   
			   
			   function getParamName(attr) {
			 	  let match = RegExp(`[?&]${attr}=([^&]*)`) //分组运算符是为了把结果存到exec函数返回的结果里
			 		.exec(window.location.search)
			 	  //["?id=小黄", "小黄", index: 0, input: "?id=小黄&age=23"]
			 	  return match && decodeURIComponent(match[1].replace(/\+/g, ' ')) // url中+号表示空格,要替换掉
			 	}
			 	
			 	var date =  convertDateFromString("2018-06-06 16:33:20");
			 
			 console.log(date,date.getTime());
			 var s= convertDateFromString('2018-06-02 23:59:03');
			 console.log(s,s.getTime());
			 // 字符串转日期
			 function convertDateFromString(dateString) { 
			 if (dateString) { 
			 var arr1 = dateString.split(" "); 
			 var sdate = arr1[0].split('-'); 
			 var stime = arr1[1].split(':'); 
			 var date = new Date(sdate[0], sdate[1]-1, sdate[2],stime[0],stime[1],stime[2]); 
			 return date;
			 } 
			 }
			 	
			 	/**
			  * 日期转字符串
			  * @param fmt
			  * @returns
			  */
			 Date.prototype.Format = function (fmt) {
			     var o = {
			         "M+": this.getMonth() + 1, //月份 
			         "d+": this.getDate(), //日 
			         "h+": this.getHours(), //小时 
			         "m+": this.getMinutes(), //分 
			         "s+": this.getSeconds(), //秒 
			         "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
			         "S": this.getMilliseconds() //毫秒 
			     };
			     if (/(y+)/.test(fmt))
			         fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
			     for (var k in o){
			         if (new RegExp("(" + k + ")").test(fmt)) {
			             fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
			         }
			     }
			     return fmt;
			 }
			
			 function scrollToEnd(){//滚动到底部
			            // var h = $(document).height()-$(window).height();
			             //$(document).scrollTop(h); 
						 var h = $("#msg-list").height()-$(window).height()+200;
						 $(".mui-content").scrollTop(h);
						// $("#msg-list").offset().top=200;
						// document.body.scrollTop="100px";
						//mui('#msg-list').scroll().scrollToBottom(900);
						 console.log(h, $(".mui-content").offset().top ,$(".mui-content")[0].scrollTop ,"-------------------------滚动到底部--------------------------",$("#msg-list").height(),$(window).height())
			 }
			 function scrollToTop(){//滚动到底部
			            // var h = $(document).height()-$(window).height();
			             $(document).scrollTop(-40); 
			 }
			 //转义html标签
			 function HTMLEncode(html) {
			  // var temp = document.createElement("div");
			  // (temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
			  // var output = temp.innerHTML;
			  // temp = null;
			  // return output;
			  return html;
			 }
			 
			 
			 function callWeex(isOpen){
			 	//alert(typeof window.qswebview.actionFromJsWithParam);
			 	if(window.qswebview&&(typeof window.qswebview.actionFromJsWithParam=="function"))
			 	window.qswebview.actionFromJsWithParam("{eventName:'chatIM_event',msg:'"+isOpen+"'}");
			 	if(typeof window.actionFromJsWithParam=="function")//ios
			 	window.actionFromJsWithParam({eventName:'chatIM_event',msg:""+isOpen});
			 	if(typeof window.postMessage=="function")
			 	window.postMessage({eventName:'chatIM_event',msg:""+isOpen},"111");
			 }
			 
			 
			 
			 
			document.getElementById('sendbtn').addEventListener('tap',function(){
				//$("#send0").show();
				$("#send1").show();
				$("#fotterleft").css("width","50px");
				console.log("----------");
				//发送请求
				//$("#msg-text").html().replace(/"/g,'\'');
				$humanAjaxFunc('/im/sendMessage',{
								data:{
									
									msgType:4  //4是文斌内容，3是图片
									,data_msg:$("#msg-text").html().replace(/"/g,'\'')
									,appType:1
									,group_id:group_id
									,myid:getQueryString("phone")//localStorage.getItem("telephone")
								},
								crossDomain :true,
								dataType:'json',//服务器返回json格式数据
								type:'post',//HTTP请求类型
								success:function(data){
								
									//获得服务器响应
									console.log(data);
									
									$("#msg-text").html("");
									localStorage.yuancount=parseInt(localStorage.yuancount)+1
									updateAppHotspot({
										
										phone:localStorage.telephone,
										modular:"chat",
										otherid:localStorage.groupid,
										number:localStorage.yuancount
										
									});
								},error:function(e){
									
									console.log(e.responseJSON);
								
									
								}
							}
							
							);
				
			});
			
			
			
			function  startQueryGrapGifts(){
				queryGrapGifts({group_id:group_id},function(data){
					var groups = JSON.parse(localStorage.groups);
					var persons= JSON.parse(localStorage.persons);
					var peoples=[];
					var list = data.data;
					for( var i=0,m=groups.length;i<m;i++ ){
						var item = groups[i];
						
						if(localStorage.groupid==item.group_id){
							var ids = groups[i].ids.split(",");
							
							for(var k in ids){
								
								var myid=ids[k];
								for( var j=0,n=persons.length;j<n;j++ ){
									if(myid==persons[j].myid){
										peoples.push(persons[j]);
									}
								}
								
							}
							
							break;
						}			
						
					}
					console.log(peoples);
					var openlist=[];//把个人抢的去掉type==0的总的留下
					for(var i=0,m=list.length;i<m;i++){
						var item = list[i];
						//item.giftcount=0;
						if(item.type==0){
							openlist.push(item);
						}
						
					}
					
					console.log(openlist);
					
					
					var myList=[];
					for(var i=0,m=list.length;i<m;i++){
						var item = list[i];
						for(var j=0,n=openlist.length;j<n;j++){
							var open = openlist[j];
							//console.log(j,openlist[j]);
							if(item.order_no_child==open.order_no_child&&item.type==1){
								
								//
								openlist[j].count-=1;
								
								if(item.phone==localStorage.telephone){
									//我自己已经领取过
									openlist[j].have = "true";
									
								}
								
							}
							
							
						}
						
					}
					//console.log(openlist[1]);
					
					$("#msg-list").find(".msg-item").each(function(index,item){
						//console.log(i,item);
						if($(item).attr("msg-type")=="surprise"){
							if(openlist.length<1)return;
							//var open = openlist.shift();
							for(var i=0,m=openlist.length;i<m;i++){
								var open = openlist[i];
								//console.log('-------------',open.order_no_child);
								var src = $(item).find(".surprise").attr("src");
								var str = "orderNoChild=";
								var startIndex = src.indexOf(str);
								var old = src.substring(startIndex+str.length);
								//console.log('-------------',old);
								if(open.order_no_child==old){
									$(item).find(".surprise").attr("order_no_child",open.order_no_child);
									if(open.count >0 ){
										$(item).find(".surprise").attr("iscan","true");
										
									}
									
									if(open.have=="true"){
										$(item).find(".surprise").attr("getsurprise","true");
										
									}
									break;
								}
							}
							
							
							
						}
						
					});
					
					
					
					
					
					
				})
			}
			
			/**查询所有的礼物**/
			function queryGrapGifts(param,callback){
				$humanAjaxFunc('/shop/queryGrapGifts',{
								data:param,
								crossDomain :true,
								dataType:'json',//服务器返回json格式数据
								type:'post',//HTTP请求类型
								success:function(data){
								
									//获得服务器响应
									console.log(data);
									if(typeof callback == "function"){
										callback(data)
									}
									
								},error:function(e){
									
									console.log(e.responseJSON);
								
									
								}
							}
							
							);
				
			}
			
			//发完礼品后,像群组发送消息
			function sendMessageGrapGifts(callback){
				
				
				
				$humanAjaxFunc('/im/sendMessage',{
								data:{
									
									msgType:89  //4是文斌内容，3是图片,88抢礼品图片,89抢到礼品
									,data_msg:"../surprise/images/sendsus.jpg?orderNoChild="+order_no_child
									,appType:1
									,group_id:localStorage.groupid
									,myid:localStorage.telephone//localStorage.getItem("telephone")
								},
								crossDomain :true,
								dataType:'json',//服务器返回json格式数据
								type:'post',//HTTP请求类型
								success:function(data){
								
									//获得服务器响应
									console.log(data);
									
									if(typeof callback == "function"){
										callback(data)
									}
									localStorage.yuancount=parseInt(localStorage.yuancount)+1
									updateAppHotspot({
										
										phone:localStorage.telephone,
										modular:"chat",
										otherid:localStorage.groupid,
										number:localStorage.yuancount
										
									});
								},error:function(e){
									
									console.log(e.responseJSON);
								
									
								}
							}
							
							);
			}
			/**发送礼品完后给服务器发送礼品数量的实时消息,服务器存数据库**/
			function addGrapGifts(orderNoChild,callback){
				
				$humanAjaxFunc('/shop/addGrapGifts',{
								data:{
									phone:localStorage.telephone
									
									,group_id:localStorage.groupid
									,order_no_child:orderNoChild
									
								},
								crossDomain :true,
								dataType:'json',//服务器返回json格式数据
								type:'post',//HTTP请求类型
								success:function(data){
								
									//获得服务器响应
									console.log(data);
									
									if(typeof callback == "function"){
										callback(data)
									}
									
									
								},error:function(e){
									
									console.log(e.responseJSON);
								
									
								}
							}
							
							);
			}
			
			
			
			function queryPerson(orderNoChild){
				$humanAjax('/shop/queryOrderNo',{
										data:{
											
											orderNoChild:orderNoChild,
											phone:localStorage.telephone
										},
										crossDomain :true,
										dataType:'json',//服务器返回json格式数据
										type:'post',//HTTP请求类型
										success:function(data){
										
											//获得服务器响应
											console.log(data);
										if(data&&data.data&&data.data.length==1){
											var param = data.data[0];
											var date = (new Date).Format("yyyyMMddHHmmss");
											var orderNoChild = localStorage.telephone+date+Math.ceil(Math.random()*100);
											addPersonOrder({
												orderNo:param.order_no
												,sendPhone:param.send_phone
												,getPhone:localStorage.telephone//前面本来是对方的手机号现在存群组号,这里改成抢人的手机号
												,surpriseType:4
												,orderNoChild:orderNoChild
												,giftName:param.gift_name
												,giftType:param.gift_type
												,giftCount:param.gift_count
												,giftUnit:param.gift_unit
												,giftPrice:param.gift_price
												,appellation:param.appellation
												,inscription:param.inscription
												,content:param.content
												,status:7//抢礼品未领取
												,sendTime:new Date
												,sendType:0
												,getType:0
												
											})
										}
											
										},error:function(e){
											
											console.log(e.responseJSON);
										
											
										}
									},localStorage.getItem("token")||"11111111111111111111");
			}
			
			
			/**强盗后增加订单**/
			function addPersonOrder(param){
				$humanAjax(JS_PATH+'/personOrder/addcaht',{
										data:param,
										crossDomain :true,
										dataType:'json',//服务器返回json格式数据
										type:'post',//HTTP请求类型
										success:function(data){
											
											//获得服务器响应
											console.log(data);
										
											
										},error:function(e){
											
											console.log(e.responseJSON);
										
											
										}
									},localStorage.getItem("token")||"11111111111111111111");
			}
			
			
			
			
			
			/**
					     * ajax 上传。这里主要是上传图片。
					     */
						    function uploadByForm(target){
						    	
						    	function validate_img(a){
									 var file = a;
									 if(!/.(gif|jpg|jpeg|png|GIF|JPG|png)$/.test(file)){
									  alert("图片类型必须是.gif,jpeg,jpg,png中的一种");
									  return false;
									}else{
									     var image = new Image();
									     image.onload = function(){
									     	var height = image.height;
										     var width = image.width;
										     var filesize = image.fileSize;
										      alert(height+"x.."+filesize);
										     if(width>780 && height>780 /*&& filesize>102400*/){
										      alert('请上传780*780像素 或者大小小于100k的图片');
										      return false;
										     }else{
										     	alert("图片通过");
									 			return true;
										     }
									     }
									     image.src = file;
									     
									     
									 }
									 
									}
						    	
						    	
						    	var formData = new FormData(document.getElementById("myForm"));//获取表单数据
						    	$Ajax(JS_PATH_IMG+'/upload/uploader',{
										data:formData,
										crossDomain :true,
										dataType:'json',//服务器返回json格式数据
										type:'post',//HTTP请求类型
										success:function(data){
											if(data.code == 200){
												
			//									if(validate_img(data.newPath)){
													//mui.toast("图片提交成功");
													sendMessageImg(data.newPath,function(data){
														$("#previewcontioner").hide();
														$("#footer").css("bottom","0px");
														$("#pickli").attr("href","#");
													})
													
													//headerImg.src=  data.newPath
													
											}else{
												mui.toast("提交失败");
											}
											
										},error:function(e){
											mui.toast("系统出错");
										}
									},true,"上传中");
						    }
			
			//发图片
			function sendMessageImg(newPath,callback){
				
				
				
				$humanAjaxFunc('/im/sendMessage',{
								data:{
									
									msgType:3  //4是文斌内容，3是图片,88抢礼品图片,89抢到礼品
									,data_msg:newPath
									,appType:1
									,group_id:localStorage.groupid
									,myid:localStorage.telephone//localStorage.getItem("telephone")
								},
								crossDomain :true,
								dataType:'json',//服务器返回json格式数据
								type:'post',//HTTP请求类型
								success:function(data){
								
									//获得服务器响应
									console.log(data);
									localStorage.yuancount=parseInt(localStorage.yuancount)+1
									updateAppHotspot({
										
										phone:localStorage.telephone,
										modular:"chat",
										otherid:localStorage.groupid,
										number:localStorage.yuancount
										
									});
									if(typeof callback == "function"){
										callback(data)
									}
									
								},error:function(e){
									
									console.log(e.responseJSON);
								
									
								}
							}
							
							);
			}
			
			
			updateAppHotspot({
				
				phone:localStorage.telephone,
				modular:"chat",
				otherid:localStorage.groupid,
				number:localStorage.yuancount
				
			});
			
			
			// 创建上传任务
			function createUpload(path) {
				//alert(JS_PATH_IMG+'/upload/uploader',)
				var task = plus.uploader.createUpload( 'https://appjingxidao.songqi.tech/upload/uploader', 
					{ method:"POST",blocksize:204800,priority:100 },
					function ( t, status ) {
						// 上传完成
						if ( status == 200 ) { 
							//alert( "上传成功: " + JSON.stringify(t) );
							var data = JSON.parse(t.responseText);
							// alert("上传成功: ");
							//$("#page6_jPanel7").find(".content_div")
							// $(".yuying").append("<div style='color: green;' class='yuying' data-href='"+data.newPath+"'>接收了一段语音点击查看</div>");
							  $(".yuying").attr("data-href",data.newPath);
							 $(".yuying").html("接收了一段语音点击查看");
							// /alert("上传成功: " + $("#page6_jPanel7").find(".content_div").length);
							var yuying = $("#page6_jPanel7").find(".yuying");
							 if(yuying.length>0){
								
								yuying[0].addEventListener('tap',function(e){
									 console.log(yuying[0],$(e.target))
									 if($(e.target).attr("data-href")){
										 var player = plus.audio.createPlayer($(e.target).attr("data-href"));
										  $(e.target).html("正在播放...");
										 player.play(function() {
										 	// playState.innerText = '点击播放';
											 console.log('play ended');
											 $(e.target).html("接收了一段语音点击查看");
										 }, function(e) {
										 	// playState.innerText = '点击播放';
											$(e.target).html("接收了一段语音点击查看");
										 });
										 
										 // var audio = document.createElement("audio");  
										 // audio.src = $(e.target).attr("data-href");  
										 // audio.play(); 
										 
										 
										 // player.addEventListener(plus.audio.AudioPlayerEvent,function(){
											//  $(e.target).html("接收了一段语音点击查看");
										 // })
										 //alert(JSON.stringify($(e.target))+'-'+$(e.target).attr("data-href"))
									 }
									
								})
							} 
							
						} else {
							alert( "上传失败: " + status );
						}
					}
				);
				task.addFile( path, {key:"file"} );
				task.addData( "string_key", "string_value" );
				//task.addEventListener( "statechanged", onStateChanged, false );
				task.start();
			}
		</script>
	</body>

</html>